Ext.define('App.datacollection.collectiontask.view.CollectionTaskList', {
    extend: 'Extend.grid.CrudGridPanel',
    alias: 'widget.CollectionTaskList',
    requires: ['App.datacollection.collectiontask.model.CollectionTaskViewModel'],
    viewModel: 'CollectionTaskViewModel',
    bind: {
        store: '{Query}',
        columns: '{columns}',
        search: '{search}'
    },
    config: {
        tbar: {
            quickCreate: {
                hidden: true
            },
            execute: {
                text: "立即执行",
                handler: function () {
                    var me = this.up('CrudGridPanel');
                    me.executeHandler.call(me);
                }
            }
        }
    },
    editor: {
        formClazz: 'App.datacollection.collectiontask.view.CollectionTaskEditor',
        save: 'datacollection/collectiontask/save',
        get: 'datacollection/collectiontask/get_by_id',
        del: 'datacollection/collectiontask/deletes',
        model: 'App.datacollection.collectiontask.model.CollectionTaskModel'
    },
    addHandler: function () {
        this.editHandler(null, false, {
            project: {
                id: this.projectId
            },
            repeatMode: '每周',
            disabled: false
        });
    },
    executeHandler: function () {
        var me = this;
        var selection = me.getSelectionModel().getSelection();
        if (selection.length > 0) {
            var data = selection[0].data;
            Ext.Ajax.request({
                url: 'datacollection/collectionschedule/execute_once',
                params: {
                    // name: data.name,
                    executor: "测试执行人",
                    taskId: data.id
                },
                success: function (resp) {
                    try {
                        if (resp.result.success) {
                            me.reload();
                        }
                    } finally {
                        me.unmask();
                    }
                },
                failure: function () {
                    me.unmask();
                }
            });
        }
    }
});